#include <iostream>
#include <cstring>
using namespace std;
struct node
{
    node *lchild= nullptr;
    node *rchild= nullptr;
    char data;
};

char a[27],b[27];
int t=0;

void selve(node * &T,int left,int right)
{
    if(left>=right)
    {
        T = nullptr;
        return;
    }
    char c=a[t];
    t++;
    int k=0;
    for(int i=left;i<right;i++)
    {
        if(b[i]==c)
        {
            k=i;
            break;
        }
    }
    T=new node;
    T->data=c;

    selve(T->lchild,left,k);
    selve(T->rchild,k+1,right);
}

void print(node * T)
{
    if(nullptr!=T)
    {
        print(T->lchild);
        print(T->rchild);
        cout<<T->data;
    }
}


int main() {

    while(scanf("%s",a)!=EOF)
    {
        t=0;
        scanf("%s",b);
        int lenth=strlen(a);
        node *T;
        selve(T,0,lenth);
        print(T);
        cout<<endl;
    }
    return 0;
}
